package com.mtwp.dfs;

import com.twp.auth.annotation.EnableAuth;
import com.twp.auth.myinterface.AuthInfo;
import com.twp.common.component.process.statemachine.annotation.IMapFunctionListenerProcess;
import com.twp.common.component.process.statemachine.base.DefaultStateNodeComponent;
import com.twp.common.component.process.statemachine.base.StateComponent;
import com.twp.common.component.process.statemachine.demo.DemoFuncMap;
import com.twp.common.component.process.statemachine.domain.StateNode;
import com.twp.common.component.process.statemachine.domain.iinterface.IMapRouterProcessStateNodeFunc;
import com.twp.common.component.process.statemachine.translate.ITranslateState;
import com.twp.common.component.process.statemachine.translate.impl.TranslateStateCode;
import com.twp.common.tuple.RequestDto;
import com.twp.common.tuple.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.javatuples.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.security.Principal;
import java.util.HashMap;
import java.util.Map;

@EnableAuth(
        basePackages = {EnableAuth.basePackage,"com.mtwp.*"},
        restBasePackages = ".*[.reset.].*"
)
@SpringBootApplication
@SpringCloudApplication
@EnableTransactionManagement
@EnableScheduling
@EnableZuulProxy
@Slf4j
public class Application implements AuthInfo {
    public static void main(String[] args){
        SpringApplication.run(Application.class,args);
    }

    @Autowired
    ITranslateState<StateNode,Map,Map<StateNode,IMapRouterProcessStateNodeFunc<StateNode>>,ResultDTO,Exception> iTranslateState;

    @Autowired
    IMapFunctionListenerProcess<StateNode,Map<StateNode,IMapRouterProcessStateNodeFunc<StateNode>>> iMapFunctionListenerProcess;

//    @Bean
//    public CommandLineRunner schedulerRunner() {
//        return new CommandLineRunner(){
//            @Override
//            public void run(String... args) throws Exception {
////                ResultDTO resultDTO =
////                        new StateComponent<
////                                StateNode,
////                                Map,
////                                Map<StateNode, IMapRouterProcessStateNodeFunc<StateNode>>,
////                                ResultDTO,Exception
////                                >
////                                (DemoFuncMap.builder().build()){
////                            @Override
////                            public StateNode onCreate() {
////                                return StateNode
////                                        .builder()
////                                        .nodeCode("t_test01")
////                                        .requestDto(new RequestDto(){{
////                                            setPrincipal(new Principal() {
////                                                @Override
////                                                public String getName() {
////                                                    return "f170427";
////                                                }
////                                            });
////                                            setData(new HashMap(){{
////                                                put("name","twp");
////                                            }});
////                                        }})
////                                        .build();
////                            }
////
////                            @Override
////                            public Pair<Map, StateNode> onStart() {
////                                return Pair.with(new HashMap(),new StateNode().setNodeCode("t_test02"));
////                            }
////
////                            @Override
////                            public void onException(Exception e) {
////
////                            }
////
////                            @Override
////                            public void onDestroy() {
////
////                            }
////                        }.setIMapFunctionListenerProcess(iMapFunctionListenerProcess).setITranslateState(iTranslateState).runOnResp();
//                ResultDTO resultDTO = new DefaultStateNodeComponent(DemoFuncMap.builder().build()){
//                            @Override
//                            public StateNode onCreate() {
//                                return StateNode
//                                        .builder()
//                                        .nodeCode("t_test01")
//                                        .requestDto(new RequestDto(){{
//                                            setPrincipal(new Principal() {
//                                                @Override
//                                                public String getName() {
//                                                    return "f170427";
//                                                }
//                                            });
//                                            setData(new HashMap(){{
//                                                put("name","twp");
//                                            }});
//                                        }})
//                                        .build();
//                            }
//
//                            @Override
//                            public Pair<Map, StateNode> onStart() {
//                                return Pair.with(new HashMap(),new StateNode().setNodeCode("t_test02"));
//                            }
//
//                            @Override
//                            public void onException(Exception e) {
//
//                            }
//
//                            @Override
//                            public void onDestroy() {
//
//                            }
//                        }.setIMapFunctionListenerProcess(iMapFunctionListenerProcess).setITranslateState(iTranslateState).runOnResp();
//                log.info(resultDTO.toString());
//            }
//        };
//    }
}
